package com.richie696.rabbit.product.service.impl;

import com.richie696.rabbit.commons.ExecuteResult;
import com.richie696.rabbit.product.domain.ProductInfo;
import com.richie696.rabbit.product.mapper.ProductMapper;
import com.richie696.rabbit.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class ProductServiceImpl implements ProductService {

    private final ProductMapper productMapper;

    @Autowired
    public ProductServiceImpl(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }

    @Override
    public ExecuteResult<ProductInfo> findProductById(Long id) {
        ProductInfo productInfo = productMapper.selectById(id);
        if (Objects.isNull(productInfo)) {
            return ExecuteResult.getErrorResult("该商品已售罄或已下架。");
        }
        return ExecuteResult.getSuccess(productInfo);
    }


}
